const fs = require('fs');
const argvs = process.argv;
const src = __dirname + '/' + argvs[2];
const dest = __dirname + '/' + argvs[3];

if (!fs.existsSync(src)) {
    console.log('file is not exists!')
    return
}
const stat = fs.lstatSync(src);
const handlerRemoveDir = (dir) => {
    let files = fs.readdirSync(dir)
    files && files.forEach(file=>{
        const destFile = `${dest}/${file}`;
        fs.rmSync(destFile);
    })

}
if (stat.isDirectory()) {
    if (fs.existsSync(dest)) {
        console.log("目标目录已存在，请重新输入！")
        handlerRemoveDir(dest)
        return
    }
    fs.mkdirSync(dest);
    const files = fs.readdirSync(src);
    console.log(files)
    files && files.forEach(file=>{
        const srcFile = `${src}/${file}`;
        const destFile = `${dest}/${file}`
        fs.copyFileSync(srcFile,destFile)
        console.log('======',file)
    })
    console.log('目录复制成功！')
}

if (stat.isFile()) {
    if (fs.existsSync(dest)) {
        console.log("目标文件已存在，请重新输入！")
        return
    }
    fs.copyFileSync(src, dest);
    console.log('文件复制成功！')
}